package com.hacpai.android.md.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.hacpai.android.md.model.entity.Article;
import com.hacpai.android.md.model.entity.ArticleSimple;
import com.hacpai.android.md.model.entity.User;
import com.hacpai.android.md.ui.fragment.UserDetailItemFragment;

import java.util.ArrayList;
import java.util.List;

public class UserDetailPagerAdapter extends FragmentPagerAdapter {

    private final List<UserDetailItemFragment> fmList = new ArrayList<>();

    //对应3个fmTitile
    public static final int POST = 0;
    public static final int WATCH = 1;
    public static final int COMMENT = 2;

    private final String[] titles = {
            "最新发布",
            "关注帖子",
            "最近回复",
    };

    public UserDetailPagerAdapter(@NonNull FragmentManager manager) {
        super(manager);
        fmList.add(new UserDetailItemFragment());
        fmList.add(new UserDetailItemFragment());
        fmList.add(new UserDetailItemFragment());
    }


    public void update(@NonNull int index , @NonNull List<Article> articleList) {
        List<ArticleSimple> articleSimpleList = new ArrayList<>();
        for (Article article : articleList) {
            articleSimpleList.add(article);
        }
        fmList.get(index).notifyDataSetChanged(articleSimpleList);
    }

    @Override
    public Fragment getItem(int position) {
        return fmList.get(position);
    }

    @Override
    public int getCount() {
        return fmList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

}
